<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<div class="layui-container">
    <form class="layui-form layui-row layui-col-space10">
        <div class="layui-col-md4 layui-col-md-offset4 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">维修员</label>
                        <input type="hidden" name="id" class="rsId">
                        <div class="layui-input-block">
                            <select id="serviceId" name="serviceId" lay-filter="serviceId">
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md4 layui-col-md-offset4 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <div class="layui-input-block">
                            <a class="layui-btn layui-btn-sm" lay-filter="assignServiceman" lay-submit><i class="layui-icon">&#xe605;</i>添加</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','jquery'],function () {
        var form = layui.form,
            $ = layui.jquery;
        $.ajax({
            url:'/servicemanController/all',
            type:'GET',
            success:function (res) {
                var options = "";
                $.each(res.data,function (index,item) {
                    options +=  "<option value='"+item.id+"'>"+item.serviceName+"</option>";
                });
                $("#serviceId").append(options);
                form.render();
            }
        });


        form.on("submit(assignServiceman)",function(obj) {
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            var data = obj.field;
            console.log(data);
            /**
             * 请求后台
             */
            $.ajax({
                type: 'POST',
                url: '/reListController/assign',
                data: JSON.stringify(data),
                dataType: 'json',
                contentType: 'application/json',
                success: function (res) {
                    /**
                     * 添加成功后回调
                     **/
                    setTimeout(function () {
                        top.layer.close(index);
                        top.layer.msg("指派成功");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    }, 500);
                    return false;
                }
            });
        });
    })
</script>
</html>